package com.project.controller;

import com.project.dto.ApprovalPageDTO;
import com.project.dto.RequestDTO;
import com.project.result.Result;
import com.project.service.ApprovalsService;
import com.project.vo.ApprovalDetailVO;
import com.project.vo.ApprovalsPageVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/approvals")
@Slf4j
public class ApprovalsController {
    @Autowired
    private ApprovalsService approvalsService;

    /**
     * 根据id查询审批实例
     * @return
     */
    @GetMapping("/{id}")
    public Result<ApprovalDetailVO> getApprovalsById(@PathVariable Integer id){

        ApprovalDetailVO approvalDetailVO=approvalsService.getApprovalsById(id);
        return Result.success(approvalDetailVO);
    }

    @GetMapping
    public Result<ApprovalsPageVo> getApprovalsPage(ApprovalPageDTO approvalPageDTO ){
        log.info("获取审批实例列表：{}",approvalPageDTO);
        ApprovalsPageVo approvalsPageVo= approvalsService.listApprovals(approvalPageDTO);

        return  Result.success(approvalsPageVo);
    }


    @PostMapping
    public Result  approvalRequest(@RequestBody RequestDTO requestDTO){
        log.info("审批：{}",requestDTO);
        approvalsService.approvalRequest(requestDTO);
        return  Result.success();
    }
}
